package com.xian.im.modules.command.group.handler;

import com.xian.im.common.constant.CommandCodeConstant;
import com.xian.im.common.model.dto.GroupDto;
import com.xian.im.common.model.session.SessionUser;
import com.xian.im.common.proto.MsgRequest;
import com.xian.im.common.proto.MsgResponse;
import com.xian.im.common.utils.bussiness.XimResponseUtil;
import com.xian.im.common.utils.sys.SpringContextHolder;
import com.xian.im.modules.avchat.rule.MessageCheckRuleChain;
import com.xian.im.modules.command.group.AbsGroupCommand;
import com.xian.im.modules.message.GroupHandler;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-01-28 22:52
 **/
public class GroupSend extends AbsGroupCommand {

    @Override
    public void handler(MsgRequest request, String ctx, GroupDto groupEntity) {
        //是否禁言
        MessageCheckRuleChain checkRuleChain = SpringContextHolder.getBean(MessageCheckRuleChain.class);
        SessionUser sessionUser = userChannelClient().session(ctx);
        checkRuleChain.doHandler(request, sessionUser);
        MsgResponse success = XimResponseUtil.buildSuccess(sessionUser);
        success.setGroupUniqueId(groupEntity.getGroupUniqueId());
        GroupHandler.groupSendAll(success, groupEntity.getGroupUniqueId());
    }

    /**
     * 群组code
     *
     * @return
     */
    @Override
    public String cmdCode() {
        return CommandCodeConstant.GROUP_SEND;
    }
}
